package com.motorwaymanage.impl;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.motorwaymanage.beans.LocationInfo;
import com.motorwaymanage.biz.ILocationInfoBiz;
import com.motorwaymanage.dao.DBAccess;

public class LocationInfoBizImpl implements ILocationInfoBiz{
	private DBAccess db=new DBAccess();
	@Override
	public int addLocationInfo(LocationInfo li) {
		SqlSession session=null;
		int result=0;
		try {
			session=db.getSqlSession();
			ILocationInfoBiz locationInfoBiz=session.getMapper(ILocationInfoBiz.class);
			result=locationInfoBiz.addLocationInfo(li);
			session.commit();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}
	@Override
	public List<String> selectLaddr() {
		SqlSession session=null;
		List<String> result=null;
		try {
			session=db.getSqlSession();
			ILocationInfoBiz locationInfoBiz=session.getMapper(ILocationInfoBiz.class);
			result=locationInfoBiz.selectLaddr();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}
	@Override
	public List<LocationInfo> getAllLocationInfo() {
		SqlSession session=null;
		List<LocationInfo> result=null;
		try {
			session=db.getSqlSession();
			ILocationInfoBiz locationInfoBiz = session.getMapper(ILocationInfoBiz.class);
			result = locationInfoBiz.getAllLocationInfo();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}
	@Override
	public int modifyLocation(LocationInfo li) {
		SqlSession session=null;
		int result=0;
		try {
			session=db.getSqlSession();
			ILocationInfoBiz locationInfoBiz=session.getMapper(ILocationInfoBiz.class);
			result=locationInfoBiz.modifyLocation(li);
			session.commit();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}
	
	@Override
	public int modifyAokInfo(String laddr) {
		SqlSession session=null;
		int result=0;
		try {
			session=db.getSqlSession();
			ILocationInfoBiz locationInfoBiz=session.getMapper(ILocationInfoBiz.class);
			result=locationInfoBiz.modifyAokInfo(laddr);
			if(result == 1) {
				session.commit();
			} else {
				session.rollback();
				result = 0;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}
	@Override
	public int modifyAstInfo(String laddr) {
		SqlSession session=null;
		int result=0;
		try {
			session=db.getSqlSession();
			ILocationInfoBiz locationInfoBiz=session.getMapper(ILocationInfoBiz.class);
			result=locationInfoBiz.modifyAstInfo(laddr);
			if(result == 1) {
				session.commit();
			} else {
				session.rollback();
				result = 0;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}
}
